import { IPSAppFunc } from './ipsapp-func';
import { IPSAppView } from '../view/ipsapp-view';
import { IPSNavigateContext } from '../../control/ipsnavigate-context';
import { IPSNavigateParam } from '../../control/ipsnavigate-param';
import { IPSLanguageRes } from '../../res/ipslanguage-res';
import { IPSUIAction } from '../../view/ipsuiaction';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSAppFuncImpl extends PSModelObjectImpl implements IPSAppFunc {
  get appFuncType(): 'APPVIEW' | 'OPENHTMLPAGE' | 'PDTAPPFUNC' | 'UIACTION' | 'JAVASCRIPT' | 'CUSTOM' {
    return this.M.appFuncType;
  }

  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get funcSN(): string {
    return this.M.funcSN;
  }

  get htmlPageUrl(): string {
    return this.M.htmlPageUrl;
  }

  get jSCode(): string {
    return this.M.jSCode;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  protected namepslanguageres: IPSLanguageRes | null = null;

  getNamePSLanguageRes(): IPSLanguageRes | null {
    if (this.namepslanguageres != null) return this.namepslanguageres;
    const value = this.M.getNamePSLanguageRes;
    if (value == null) {
      return null;
    }
    this.namepslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getNamePSLanguageRes') as IPSLanguageRes;
    return this.namepslanguageres;
  }

  get namePSLanguageRes(): IPSLanguageRes | null {
    return this.getNamePSLanguageRes();
  }

  getNamePSLanguageResMust(): IPSLanguageRes {
    const value = this.getNamePSLanguageRes();
    if (value == null) {
      throw new Error('未指定名称语言资源');
    }
    return value;
  }

  get openMode(): 'INDEXVIEWTAB' | 'INDEXVIEWPOPUP' | 'INDEXVIEWPOPUPMODAL' | 'HTMLPOPUP' | 'TOP' {
    return this.M.openMode;
  }

  get openViewParam(): IModel {
    return this.M.openViewParam;
  }

  protected psappview: IPSAppView | null = null;

  getPSAppView(): IPSAppView | null {
    if (this.psappview != null) return this.psappview;
    const value = this.M.getPSAppView;
    if (value == null) {
      return null;
    }
    this.psappview = this.getPSModel4('app.view.IPSAppView', value, 'getPSAppView') as IPSAppView;
    return this.psappview;
  }

  get psAppView(): IPSAppView | null {
    return this.getPSAppView();
  }

  getPSAppViewMust(): IPSAppView {
    const value = this.getPSAppView();
    if (value == null) {
      throw new Error('未指定打开视图');
    }
    return value;
  }

  protected psnavigatecontexts: IPSNavigateContext[] | null = null;

  getPSNavigateContexts(): IPSNavigateContext[] | null {
    if (this.psnavigatecontexts == null) {
      this.psnavigatecontexts = this.fillChildListModel(this.M.getPSNavigateContexts, 'control.IPSNavigateContext') as IPSNavigateContext[];
    }
    return this.psnavigatecontexts;
  }

  get psNavigateContexts(): IPSNavigateContext[] | null {
    return this.getPSNavigateContexts();
  }

  findPSNavigateContext(objKey: any): IPSNavigateContext | null {
    return this.getPSModel5('control.IPSNavigateContext', this.getPSNavigateContexts(), objKey) as IPSNavigateContext;
  }

  protected psnavigateparams: IPSNavigateParam[] | null = null;

  getPSNavigateParams(): IPSNavigateParam[] | null {
    if (this.psnavigateparams == null) {
      this.psnavigateparams = this.fillChildListModel(this.M.getPSNavigateParams, 'control.IPSNavigateParam') as IPSNavigateParam[];
    }
    return this.psnavigateparams;
  }

  get psNavigateParams(): IPSNavigateParam[] | null {
    return this.getPSNavigateParams();
  }

  findPSNavigateParam(objKey: any): IPSNavigateParam | null {
    return this.getPSModel5('control.IPSNavigateParam', this.getPSNavigateParams(), objKey) as IPSNavigateParam;
  }

  get psPDTAppFuncId(): string {
    return this.M.getPSPDTAppFuncId;
  }

  getPSPDTAppFuncId(): string {
    return this.M.getPSPDTAppFuncId;
  }

  protected psuiaction: IPSUIAction | null = null;

  getPSUIAction(): IPSUIAction | null {
    if (this.psuiaction != null) return this.psuiaction;
    const value = this.M.getPSUIAction;
    if (value == null) {
      return null;
    }
    this.psuiaction = this.getPSModel4('view.IPSUIAction', value, 'getPSUIAction') as IPSUIAction;
    return this.psuiaction;
  }

  get psUIAction(): IPSUIAction | null {
    return this.getPSUIAction();
  }

  getPSUIActionMust(): IPSUIAction {
    const value = this.getPSUIAction();
    if (value == null) {
      throw new Error('未指定应用界面行为');
    }
    return value;
  }

  get tooltip(): string {
    return this.M.tooltip;
  }

  protected tooltippslanguageres: IPSLanguageRes | null = null;

  getTooltipPSLanguageRes(): IPSLanguageRes | null {
    if (this.tooltippslanguageres != null) return this.tooltippslanguageres;
    const value = this.M.getTooltipPSLanguageRes;
    if (value == null) {
      return null;
    }
    this.tooltippslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getTooltipPSLanguageRes') as IPSLanguageRes;
    return this.tooltippslanguageres;
  }

  get tooltipPSLanguageRes(): IPSLanguageRes | null {
    return this.getTooltipPSLanguageRes();
  }

  getTooltipPSLanguageResMust(): IPSLanguageRes {
    const value = this.getTooltipPSLanguageRes();
    if (value == null) {
      throw new Error('未指定操作提示语言资源');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userData(): string {
    return this.M.userData;
  }

  get userData2(): string {
    return this.M.userData2;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get systemReserved(): boolean {
    return this.M.systemReserved != null ? this.M.systemReserved : false;
  }

  get cls(): string {
    return 'PSAppFuncImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'app.func.IPSAppFunc' || cls == 'control.IPSNavigateParamContainer') return true;
    return super.instanceof(cls);
  }
}
